From f682aced273e00d167672fa6fd22d7f50faec853 Mon Sep 17 00:00:00 2001 From: Nik Everett Date: Thu, 23 Oct 2014 20:15:18 -0400 Subject: [PATCH] Allow search to return matching category Will be used by Cirrus. Change-Id: I60e6b19d3b59ebf9bb45cc61d16936dfc7e4c708 --- includes/search/SearchResult.php | 7 +++++++ includes/specials/SpecialSearch.php | 15 +++++++++++---- languages/i18n/en.json | 1 + languages/i18n/qqq.json | 1 + 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/includes/search/SearchResult.php b/includes/search/SearchResult.php index aeaba8df32..2cdf9f4142 100644 --- a/includes/search/SearchResult.php +++ b/includes/search/SearchResult.php @@ -185,6 +185,13 @@ class SearchResult { return null; } + /** + * @return string Highlighted relevant category name or '' if none or not supported + */ + public function getCategorySnippet() { + return ''; + } + /** * @return string Timestamp */ diff --git a/includes/specials/SpecialSearch.php b/includes/specials/SpecialSearch.php index 3cb5444617..895f1e86b7 100644 --- a/includes/specials/SpecialSearch.php +++ b/includes/specials/SpecialSearch.php @@ -621,8 +621,9 @@ class SpecialSearch extends SpecialPage { $redirectText = $result->getRedirectSnippet(); $sectionTitle = $result->getSectionTitle(); $sectionText = $result->getSectionSnippet(); - $redirect = ''; + $categorySnippet = $result->getCategorySnippet(); + $redirect = ''; if ( !is_null( $redirectTitle ) ) { if ( $redirectText == '' ) { $redirectText = null; @@ -635,7 +636,6 @@ class SpecialSearch extends SpecialPage { } $section = ''; - if ( !is_null( $sectionTitle ) ) { if ( $sectionText == '' ) { $sectionText = null; @@ -647,6 +647,13 @@ class SpecialSearch extends SpecialPage { ""; } + $category = ''; + if ( $categorySnippet ) { + $category = "" . + $this->msg( 'search-category' )->rawParams( $categorySnippet )->text() . + ""; + } + // format text extract $extract = "
" . $result->getTextSnippet( $terms ) . "
"; @@ -691,7 +698,7 @@ class SpecialSearch extends SpecialPage { $thumb->toHtml( array( 'desc-link' => true ) ) . '' . '' . - "{$link} {$redirect} {$section} {$fileMatch}" . + "{$link} {$redirect} {$category} {$section} {$fileMatch}" . $extract . "
{$desc} - {$date}
" . '' . @@ -712,7 +719,7 @@ class SpecialSearch extends SpecialPage { &$html ) ) ) { $html = "
  • " . - "{$link} {$redirect} {$section} {$fileMatch}
    {$extract}\n" . + "{$link} {$redirect} {$category} {$section} {$fileMatch} {$extract}\n" . "
    {$size} - {$date}
    " . "
  • \n"; } diff --git a/languages/i18n/en.json b/languages/i18n/en.json index b6ee3c76c0..1c6890c5cd 100644 --- a/languages/i18n/en.json +++ b/languages/i18n/en.json @@ -887,6 +887,7 @@ "search-result-category-size": "{{PLURAL:$1|1 member|$1 members}} ({{PLURAL:$2|1 subcategory|$2 subcategories}}, {{PLURAL:$3|1 file|$3 files}})", "search-redirect": "(redirect $1)", "search-section": "(section $1)", + "search-category": "(category $1)", "search-file-match": "(matches file content)", "search-suggest": "Did you mean: $1", "search-interwiki-caption": "Sister projects", diff --git a/languages/i18n/qqq.json b/languages/i18n/qqq.json index edd522ac72..61fbc88bdd 100644 --- a/languages/i18n/qqq.json +++ b/languages/i18n/qqq.json @@ -1050,6 +1050,7 @@ "search-result-category-size": "Parameters:\n* $1 - number of members in this category. $1 is equal to $2+$3.\n* $2 - number of subcategories\n* $3 - number of files", "search-redirect": "\"Redirect\" is a noun here, not a verb.\n\nParameters:\n* $1 - a link to the redirect to the page (so, $1 is the page that the search result is redirected '''from''')", "search-section": "This text will be shown on the search result listing after the page title of a result if the search algorithm thinks that section is more relevant than the rest of the page. $1 is a section title.\n{{Identical|Section}}", + "search-category": "This text will be shown on the search result listing after the page title of a result if the search algorithm thinks that the page being in a particular category is relevant. $1 is the category's name with any matching portion highlighted.\n", "search-file-match": "This text will be shown on the search result listing after the page title of a result if the search engine got search results from the contents of files, rather than the pages.", "search-suggest": "Used for \"Did you mean\" suggestions:\n* $1 - suggested link", "search-interwiki-caption": "Used in [[Special:Search]], when showing search results from other wikis.", -- 2.20.1